var child4Alogin = {
	tourbillon:function(prefix,type){
		//两票 4A 登录
		localStorage.setItem('postIp',prefix.replace(/https?:\/\//ig,''))
		plus.nativeUI.showWaiting('正在跳转');
		var token = localStorage.getItem('token'),
		callback = function(data){
			/** 跳转到两票页面
			 * @method toTourbillon
			 * @param {data}
			 * @return {空} 
			*/
			var subpage_style = {
							  
			}
			
			var embed=null
			if(type == 'zwbh'){
				embed = plus.webview.create('./../../zwbh/index.html?version=1000002','tourbillon',subpage_style,{
					neomData:data,
					token:token
				});
			}else if(type == 'yxrz'){
				embed = plus.webview.create('./../../yxrz/index.html?version=1000002','tourbillon',subpage_style,{
					neomData:data,
					token:token
				});
			}else{
				embed = plus.webview.create('./../../lp/index.html?version=1000002','tourbillon',subpage_style,{
					neomData:data,
					token:token
				});
			}
			
			var ws = plus.webview.currentWebview();
			ws.append(embed);
		
			
			embed.addEventListener('loading',function(){       //当页面加载时
			    plus.nativeUI.showWaiting('',{style:'black',modal:false,background:'rgba(0,0,0,0)'});
			},false);
			embed.addEventListener('loaded',function(){       //当页面加载完成时
			    plus.nativeUI.closeWaiting();
			},false);
			plus.key.addEventListener('backbutton', function() {
			  embed.canBack(function (evt) {
			    
			          if (evt.canBack) {
			              embed.back();  
			              console.log(11)
			          } else {
						  plus.webview.close(embed)
			     
			          }  
			        
			  });  
			}); 
		}
		console.log(prefix+'/sso/fourAGetUser?accessToken='+token)
		
		mui.baseWApp.httpRequst(prefix+"/sso/fourAGetUser?accessToken="+token, {}, function(data) {
			plus.nativeUI.closeWaiting();
			if(data.ticket){
				callback(data)
			}else{
				mui.toast('登录遇到错误！')
			}
			console.log(JSON.stringify(data))
		},function(){
			mui.toast('登录遇到错误！')
			plus.nativeUI.closeWaiting();
		});
		
		
		// mui.ajax(prefix+'/sso/fourAGetAuthorize?accessToken='+token,{
		//  	data:{
		//  	},
		//  	type:'GET',//HTTP请求类型	
		// 	timeout:60000,
		//  	success:function(data){
		// 		console.log('data......',JSON.stringify(data));
		// 		plus.nativeUI.closeWaiting();
		// 		if(data.ticket){
		// 			callback(data)
		// 		}else{
		// 			mui.toast('登录遇到错误！')
		// 		}
		// 		//alert(JSON.stringify(data))
		// 	},
		// })
	},
	signIn:function(prefix){
		localStorage.setItem('postIp',prefix.replace(/https?:\/\//ig,''))
		//巡检 4A 登录
		plus.nativeUI.showWaiting('正在跳转');
		var token = localStorage.getItem('token');
		mui.baseWApp.httpRequst(prefix+"/sso/fourAGetUser?accessToken="+token, {}, function(data) {
			plus.nativeUI.closeWaiting();
			console.log(JSON.stringify(data))
			localStorage.setItem('personal', JSON.stringify(data.personal));
			localStorage.setItem('access_ticket', data.ticket);
			if(data.ticket){
				mui.openWindow({
				  url: '../../signIn/index.html',
				  id: '../index/index.html',
				  extras: {}
				});
			}else{
				mui.toast('登录遇到错误！')
			}
		},function(){
			mui.toast('登录遇到错误！')
			plus.nativeUI.closeWaiting();
		})
		return;
		
	},
	jiankong:function(prefix){
		localStorage.setItem('postIp',prefix.replace(/https?:\/\//ig,''))
		//巡检 4A 登录
		plus.nativeUI.showWaiting('正在跳转');
		var token = localStorage.getItem('token'),
		fn = function(){
			mui.openWindow({
				  url: '../../jiankong/jiankong.html',
				  id: '../jiankong/jiankong.html',
				  extras: {}
			});
			setTimeout(function(){
				var xjuser = plus.webview.getWebviewById("../tbl/xjUser.html");
				if(xjuser){
					xjuser.close('none')
				}
			},1000)
		},
		noRegFn = function(){
			mui.openWindow({
				  url: '../tbl/xjUser.html',
				  id: '../tbl/xjUser.html',
				  extras: {}
			});
		}
		mui.baseWApp.httpRequst(prefix+"/api/v2/oauth/login?accessToken="+token+'&AppId='+mui.baseWApp.AppId+'&AppKey='+mui.baseWApp.AppKey+'&AppSecret='+mui.baseWApp.AppSecret, {accessToken:token}, function(res) {
			plus.nativeUI.closeWaiting();
			console.log('res.data',JSON.stringify(res.data));
			var data = res.data
			if(data){
				localStorage.setItem('xingming', data.name);
				console.log(localStorage.getItem('xingming'));
				localStorage.setItem('userid', data.id);
				localStorage.setItem('unit', data.unit);
				localStorage.setItem('username', data.username);
				localStorage.setItem('rolesStr', data.rolesstr);
				localStorage.setItem("windName",JSON.stringify(data.windname));
				localStorage.setItem('uname', data.username);
				mui.baseWApp.httpRequst(prefix+"/api/v2/users/findUserOrg", {userid: localStorage.getItem('userid')},
				function(data) {
					console.log("获取风场信息成功" + JSON.stringify(data));
					if(data.status == 200) {
						console.log("获取风场信息成功");
						localStorage.setItem("orglist",JSON.stringify(data.data));
						localStorage.setItem("org_code",JSON.stringify(data.data[0].org_code));
						localStorage.setItem("windName",JSON.stringify(data.data[0].desc));
						console.log('org_code++++'+localStorage.getItem('org_code'));
						fn()
					}else if(data.status == "500") {
						//mui.toast(data.message);
						console.log("获取风场信息失败");
						// noRegFn()
						mui.toast('当前用户属于新用户，请先登录pc端开通权限后，再使用APP功能')
					}
				}, function() {
					console.log("获取风机失败");
				})
				
			}else{
				// noRegFn()
				mui.toast('当前用户属于新用户，请先登录pc端开通权限后，再使用APP功能')
			}
			console.log(JSON.stringify(data))
		},function(){
			mui.toast('登录遇到错误！')
			plus.nativeUI.closeWaiting();
		},'get');
		return;
	},
	ddms:function(prefix){
		localStorage.setItem('postIp',prefix.replace(/https?:\/\//ig,''))
		//一机一档 4A 登录
		plus.nativeUI.showWaiting('正在跳转');
		var token = localStorage.getItem('token'),
		ddmsToken = localStorage.getItem('ddmsToken'),
		fn = function(){
			mui.openWindow({
				  url: '../../ddms/home.html',
				  id: '../ddms/home.html',
				  extras: {}
			});
		}
		
		// if(ddmsToken){
		// 	fn();return;
		// }
		mui.baseWApp.httpRequst(prefix+"/oauth/login?accessToken="+token, {}, function(data) {
			plus.nativeUI.closeWaiting();
			var Token = data.token || ''
			if(Token){
				localStorage.setItem('ddmsToken',Token)
				fn()
			}
			console.log(JSON.stringify(data))
		},function(){
			mui.toast('登录遇到错误！')
			plus.nativeUI.closeWaiting();
		});
		return;
	},
	dzkp:function(prefix){
		localStorage.setItem('postIp',prefix.replace(/https?:\/\//ig,''))
		//一机一档 4A 登录
		plus.nativeUI.showWaiting('正在跳转');
		var token = localStorage.getItem('token'),
		ddmsToken = localStorage.getItem('ddmsToken'),
		fn = function(){
			mui.openWindow({
				  url: '../../tourbillon/index.html',
				  id: '../tourbillon/index.html',
				  extras: {}
			});
		}
		
		if(ddmsToken){
			fn();return;
		}
		mui.baseWApp.httpRequst(prefix+"/sso/fourAGetAuthorize?accessToken="+token, {}, function(data) {
			plus.nativeUI.closeWaiting();
			var Token = data.token || ''
			if(Token){
				localStorage.setItem('ddmsToken',Token)
				fn()
			}
			console.log(JSON.stringify(data))
		},function(){
			mui.toast('登录遇到错误！')
			plus.nativeUI.closeWaiting();
		});
		return;
	}
}